package com.hhw.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.hhw.entity.User;
import com.hhw.service.UserService;



/**
 * Servlet implementation class Dologin
 */
@WebServlet("/dologin")
public class Dologin extends HttpServlet {
	private static final long serialVersionUID = 1L;
   
    public Dologin() {
        super();    
    }


	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		String username =request.getParameter("username");
		String password = request.getParameter("password");
		String msg ="";
		
		User r = new User();
		r.setUser_name(username);
		r.setUser_password(password);
		System.out.println(username);
		System.out.println(password);
		
		UserService rs = new UserService();
		
		if (rs.isExist(r)) {
			List<User> rlist = rs.findUser();
			request.setAttribute("rlist", rlist);
			System.out.println("登录成功！");
			request.getRequestDispatcher("/toindex").forward(request, response);
		}else{
			System.out.println("账号或密码错误！");
			request.getRequestDispatcher("/WEB-INF/jsp/login.jsp").forward(request, response);
		}
	}
		
		
		
	}


